package cn.gson.springboot.controller;


import cn.gson.springboot.model.pojos.Complain;
import cn.gson.springboot.model.pojos.Maintenance;
import cn.gson.springboot.model.service.ComplainService;
import cn.gson.springboot.model.service.MaintenanceService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MaintenanceController {
    @Autowired
    MaintenanceService maintenanceService;

    @RequestMapping("/maintenance-list")
    @ResponseBody
    public Map<String,Object> maintenanceList(Integer page,Integer size, String search,Integer type) {
         Page<Object> obj = PageHelper.startPage(page, size);
        List<Maintenance> maintenances = maintenanceService.selectAll(search,type);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-cus-list")
    @ResponseBody
    public List<Maintenance> maintenanceList(Integer cusId) {
        List<Maintenance> maintenances = maintenanceService.selectMaintenanceCus(cusId);
        return maintenances;
    }

    @RequestMapping("/maintenance-deleteOne")
    @ResponseBody
    public void deleteOne() {
        maintenanceService.deleteOne(2);
    }

    @RequestMapping("/maintenance-selectOne")
    @ResponseBody
    public Maintenance selectOne(Integer maiId) {
        Maintenance maintenance = maintenanceService.selectOne(maiId);
        return maintenance;
    }


    @RequestMapping("/maintenance-addMaintenance")
    @ResponseBody
    public void addMaintenance(@RequestBody Maintenance maintenance) {
        System.out.println(maintenance);
        maintenanceService.addMaintenance(maintenance);
    }

    @RequestMapping("/maintenance-selectA")
    @ResponseBody
    public Map<String,Object>  selectA() {
        int count = maintenanceService.selectA();
        List<Maintenance> maintenances = maintenanceService.selectA2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-selectB")
    @ResponseBody
    public Map<String,Object>  selectB() {
        int count = maintenanceService.selectB();
        List<Maintenance> maintenances = maintenanceService.selectB2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-selectC")
    @ResponseBody
    public Map<String,Object>  selectC() {
        int count = maintenanceService.selectC();
        List<Maintenance> maintenances = maintenanceService.selectC2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-selectD")
    @ResponseBody
    public Map<String,Object>  selectD() {
        int count = maintenanceService.selectD();
        List<Maintenance> maintenances = maintenanceService.selectD2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-selectE")
    @ResponseBody
    public Map<String,Object>  selectE() {
        int count = maintenanceService.selectE();
        List<Maintenance> maintenances = maintenanceService.selectE2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-selectF")
    @ResponseBody
    public Map<String,Object>  selectF() {
        int count = maintenanceService.selectF();
        List<Maintenance> maintenances = maintenanceService.selectF2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-selectG")
    @ResponseBody
    public Map<String,Object>  selectG() {
        int count = maintenanceService.selectG();
        List<Maintenance> maintenances = maintenanceService.selectG2();
        Map<String,Object> map=new HashMap<>();
        map.put("count",count);//返回总页数
        map.put("rows",maintenances);//返回查到的数据
        return map;
    }

    @RequestMapping("/maintenance-all-list")
    @ResponseBody
    public List<Maintenance> maintenanceList() {
        List<Maintenance> main = maintenanceService.selectAll(null,null);
        return main;
    }
}